var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
});

io.on('connection', function(socket){
  console.log('a user connected');
  socket.on('disconnect', function(){
    console.log('user disconnected');
  });
socket.emit('message', { hello: '欢迎链接' });
  socket.on('my other event', function (data) {
    console.log(data);
    socket.emit('message', { hello: '发送成功' });
  });
  socket.on('say', function (data) {
    console.log(data);
    if (data.my === '吃饭') {
      io.sockets.emit('eating', { hello: '果断走起呀！' });
      return
    }
    io.sockets.emit('news', { hello: data.my });
  });
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});
